package TCP;

import java.io.*;
import java.net.*;

public class TestServer {
	public Socket socket;
	public ServerSocket ssocket;
	public PrintWriter out;
	public BufferedReader in;

	public TestServer() {
		ssocket = null;
		socket = null;
		out = null;
		in = null;
	}

	public void connect() {
		try {
			ssocket = new ServerSocket(9999);
			socket = ssocket.accept();
			out = new PrintWriter(socket.getOutputStream(), true);
			in = new BufferedReader(new InputStreamReader(
					socket.getInputStream()));
		} catch (IOException e) {
			System.err.println("Server: IO error.");
			System.exit(1);
		}
	}
	
	public void echo() {
		int i = 0;
		while(true) {
			try {
				System.out.println("server received: "+in.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			out.println(i++);
		}
	}
}